package comum;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class Mensagem {
	
	protected String ip;
	protected int port;
	protected String type;
	protected byte[] message;
	
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}

	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	
	public String getMessageString (){
		return new String(this.message);
	}
	
	public byte[] getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message.getBytes();
	}
	
	public void setMessage(byte[] buffer) {
		this.message = buffer;
	}
	
	
	public boolean send() {
		System.out.println("Enviando mensagem");
		
		Socket socket;
		try {
			socket = new Socket(this.getIp(), this.getPort());
			OutputStream socketOutput = socket.getOutputStream();
			socketOutput.write(this.message);
			socket.close();
			socketOutput.close();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}
}
